Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract the current URL from Browser

Status
Not open for further replies.

keyer

Programmer
Aug 21, 2000
18
US
Is there a way to read the current URL that appears in the browser Address window? Unfortunately, I don't have control over the browser, so what would be nice is if the Link Toolbar contained a link that called an applet from the server to read the current URL, THEN open a new browser instance and pass the current URL as a parameter as it opened a new site.
 
The syntax is :

Code:
<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
    document.write (&quot;The current URL of the browser is : &quot; + window.document.location.href);
//-->
</script>
Regards

David Byng

spider.gif


davidbyng@hotmail.com
 
OK, this gets me a lot of the way there. I can use it to write the current URL into an HTML <href> tag and put that in the Link Bar of the browser.

Next, I need the link button to link to a remote page, but pass the URL of the current page, whatever that might be, dynamically. It would output:
&quot;
My first try:
<SCRIPT LANGUAGE=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
document.write (&quot;<a href=&quot; + open(&quot; + escape(location.href) ) + &quot;>Drag This to Link Bar</a>&quot;);
//-->
</SCRIPT>


This causes the browser to open copies of itself over and over without stopping. Don't try it!

At least it's doing something. Suggestions to make it link to the new page but giving its own URL as a parameter?
 
This is what you want :

Code:
<a href=&quot;javscript:window.open('[URL unfurl="true"]http://www.newpage.com?thisURL='[/URL] + escape (location.href));&quot;>Drag this to link bar</a>
Regards

David Byng

spider.gif


davidbyng@hotmail.com
 
Yes, it does work from within the page, but when I drag the link to the Links toolbar, then click it, I get a &quot;Object Expected&quot; error.

Dragging the link to the toolbar results in a warning about an &quot;unsafe&quot; link. Could it be blocking the execution of JavaScript from the toolbar, or do we just need to refine the function?
 
David,
OK, with some minor alterations your code does exactly what I want. added &quot;javascript: void(open...&quot; and a second parameter to the open() function so that it always goes to the same page on subsequent calls.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top