Link to home
Start Free TrialLog in
Avatar of jonnyfb
jonnyfb

asked on

Load a page into another frame

Here is my HTML code

<script src="codepage.js" language="Javascript" type="text/javascript"></script>

<iframe src="blankpage.htm"  width="88" height="32"></iframe>

I need codepage.js to load this page into the iframe:

counter.asp?referer=REFERER GOES HERE

I know this may seem simple to most of you but I am a beginner to JS!

Thanks for reading this.
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

First of all neds your iframe a name:
<iframe name="myFrame" src="blankpage.htm"  width="88" height="32"></iframe>

Then your script file needs this statement:
window.onload=function(){window.frames.myFrame.src="counter.asp?referer="+document.referrer};


Avatar of jonnyfb
jonnyfb

ASKER

Is there any way which I can redirect to counter.asp?userid=...&countid=...&referer=...

If I make the script name: code.js?userid=...&countid=...

Thankyou
You cannot read the script script src in the script and you cannot change it dynamicaly.
Where should the values come from?
Avatar of jonnyfb

ASKER

Isnt there a querystring object?
The name of querystring object is: windows.location.search
And the syntax to pass the query string to the iframe is:
window.onload=function(){window.frames.myFrame.src="counter.asp?referer="+document.referrer+"&"+windows.location.search.substr(1)};

Avatar of jonnyfb

ASKER

Sorry I havent replied for soooo long. Would

windows.location.search.substr(1)

be the whole querystring?
ASKER CERTIFIED SOLUTION
Avatar of Zvonko
Zvonko
Flag of North Macedonia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Why the grading B???
Avatar of jonnyfb

ASKER

Cause it diddnt work!
Avatar of jonnyfb

ASKER

My Iframe is still just blank!
You did not state that. You simple closed the question.
I have a solution for you.
Avatar of jonnyfb

ASKER

I did not want to waste your time.
Sorry, could you tell me?
Could you ask for grade correction here:
https://www.experts-exchange.com/Community_Support/

And you do not waste my time. I like answering questions ;-)
Avatar of jonnyfb

ASKER

If I correct the grade, will you give me the solution?
My script line has two typos.
Take this one:

window.onload=function(){window.frames.myFrame.location="counter.htm?referer="+document.referrer+"&"+window.location.search.substr(1)};

Avatar of jonnyfb

ASKER

Ill test it now!
Avatar of jonnyfb

ASKER

I made counter.asp write the querystring and it said:

referer=&

So something must be wrong with window.location.search.substr(1)
That's correct.
You cannot use document.referrer localy, only on web server.
And if you want to avoid the & char when no query was in parnet window, then you need and "if" statement. But that does not hurt in standard URL syntax.

If you realy want the & only when query are passed, then rewrite it to this:

window.onload=function(){window.frames.myFrame.location="counter.htm?referer="+document.referrer+((window.location.search)?"&"+window.location.search.substr(1):"")};



Avatar of jonnyfb

ASKER

Ill try it.
Avatar of jonnyfb

ASKER

Oh no! I think Ive explained a bit wrong!!

I want this querystring:

<script src="codepage.js? >>>>>userid=...&countid=...<<<<<" language="Javascript" type="text/javascript"></script>
Avatar of jonnyfb

ASKER

Im going now but I will be back later to check what help you have given. PLZZZ I am desperate!