Passing self.location.hostname Value To *.js inclu

Results 1 to 2 of 2

Thread: Passing self.location.hostname Value To *.js inclu

  1. #1
    Join Date
    Dec 1969

    Default Passing self.location.hostname Value To *.js inclu

    I am changing some JavaScript code and have run into a snag.<BR>We currently had some JavaScript running in an index html page<BR>to redirect users based on the self.location.hostname VALUE.<BR>Apparently Search Engines don&#039;t care for this type of coding so<BR>I have to put all the redirect code into a *.js file and include it in the index.htm file. Apparently this will please the search engines (Not too sure however).<BR>Anyway, I am having problems getting the value of self.location.hostname to pass into the *.js page where all the redirect code is.<BR><BR>Example :<BR><BR>&#060;script language="JavaScript"&#062; <BR> if (self.location.hostname == "") {<BR> self.location.href =<BR> "";<BR><BR>....... More If Statements....<BR><BR>&#060;/script&#062;<BR><BR>Now this code is in a *.js page I include in the index.html page.<BR>The reference to self.location.hostname is throwing an error (because it is now included ?). Any ideas on how I can pass the self.location.hostname VALUE to the *.js page to test its value and procede with the orginal JavaScript.<BR><BR>TIA.<BR><BR>Jay Swan

  2. #2
    Join Date
    Dec 1969

    Default A really simple-minded way...

    ...just agree on a universal *global* JS variable name(s).<BR><BR>&#060;SCRIPT Language="JavaScript"&#062;<BR>// just make sure there are global references to the<BR>// thing that you want available in the .js file:<BR>var SELF = self;<BR>var SELFLOCATION = self.location;<BR>var HOSTNAME = self.location.hostname;<BR>&#060;/SCRIPT&#062;<BR><BR>and then look for that global name in the ".js" file:<BR><BR>&#060;SCRIPT Language="JavaScript" Src="funnystuff.js"&#062;&#060;/SCRIPT&#062;<BR><BR>********* file: funnystuff.js ********<BR>if (HOSTNAME == "") <BR>{<BR> SELFLOCATION.href = "http://whatever...";<BR>}<BR>...<BR>********************* *****************<BR><BR>etc.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts