Javascript in address bar

This is a discussion on "Javascript in address bar" within the JavaScript Forum section. This forum, and the thread "Javascript in address bar are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Oct 12th, 2007, 07:29
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Javascript in address bar

Marc posted about using javascript straight from the address bar.
Do you think using this method you can send someone to a page with your own JS attached to it?

Just a though
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote

  #2 (permalink)  
Old Oct 12th, 2007, 07:57
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript in address bar

Well you can access a query string with javascript so technically you could run the querystring through the function eval() and run the code on it.

It would be up to the page you're visiting though not *just* what's in the address bar.
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #3 (permalink)  
Old Oct 13th, 2007, 11:21
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Javascript in address bar

Could you show me a very basic example when you have time please?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #4 (permalink)  
Old Oct 13th, 2007, 11:50
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Javascript in address bar

Okay something like this.

I want to run this script when the new page loads:

alert("Hello, you must be pretty cool for this page to say hello");

so encode it as a url passable string

Code: Select all
var cde = encodeURIcomponent('alert("Hello, you must be pretty cool for this page to say hello");');

// send the user to where the script will be read

window.location.href = "index.html?javascript=" + cde;
Then in the page to run the script you could use something like

Code: Select all
// Use javascripts version of the PHP explode function on the search property of LOCATION which has the query string

var dtls = location.search.substring(1,location.search.length).split('&'); // split at the & signifying the separator.. the offset of 1 gets rid of the question mark
var nmeNcde = dtls[0].split('='); // split the value from the name

var cde = decodeURIcompnent(nmnNcde);// convert back to normal string

// run the code
eval(cde)

// You should get a message
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Reply With Quote
  #5 (permalink)  
Old Oct 13th, 2007, 11:52
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Javascript in address bar

Thanks, I'll try this out later, off out now!

+ rep!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
address bar doesn't change aflacduck Starting Out 10 May 29th, 2007 22:19
PHP for users IP address djme PHP Forum 3 Dec 31st, 2005 18:08
how do i get the http address? mostwanted Flash & Multimedia Forum 0 Nov 11th, 2005 14:08


All times are GMT. The time now is 00:08.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43