/    Sign up×
Community /Pin to ProfileBookmark

Passing strings

Hi, I need to pass a string from one page to another when a link is clicked. When the link is clicked I need a new page to load and for some javascript in the new page to use a string, passed from the old page (this will be the name of an image) to load the image. This will save me from having a page for each large image in my system. Any ideas to do this? I had thought of redirecting to blah.html?imname=bob and then picking up that attribute in the next page. I know this is doable in JSP but I need to do it in either Javascript or HTML.

Regards,
Matt.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliSep 16.2003 — There are fw options for you to use.

suppose image name

var img = "images/flakes.gif";

and the url to the next page is

var url = "pages/nextpage.html";

  • 1. apend the image name to the url of the next page and direct to the next page


  • window.location.href = url+"?imageName="+img;

    2.if the next page is a child window opened from the parent using

    window.open

    then you can use access these values irectly from child

    top.opener.url

  • 3. is to use cookies, set cookie at first page and then read cookie at the next page
  • Copy linkTweet thisAlerts:
    @krugosauthorSep 16.2003 — Suppose I take option 1 of those, how do I then get the image name once I'm on the new page?

    Matt.
    Copy linkTweet thisAlerts:
    @Khalid_AliSep 16.2003 — Suppose there is only one image name that you are passing to the next page.

    var searchStr = window.location.search;

    the above willreturn everything after the ? mark in the URL

    and since we know that search string format is

    imageName = images/flakes.gif

    now we need to remove the variable name and the = (comparison sign)

    var imgName = searchStr.substring(searchStr.indexOf("=")+1,searchStr.length);

    lol..I have not tested it so am hoping it will give you the correct results..
    Copy linkTweet thisAlerts:
    @CharlesSep 16.2003 — [font=georgia]There's something about the title of this thread that makes me think of my youth, the cat having ingested tinsel from the Christmas tree. With Summer at its end and a hurricane on the way it's nice to be reminded of holidays to come.[/font]
    ×

    Success!

    Help @krugos spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...