Help with code

manpreet

Power Member
Joined
Nov 3, 2011
Messages
631
Reaction score
156
I'm trying to put together a code where script is run from another page based on the parameter, example:

  • sitename.com/sitepage?script1 > This would run script in script1.php
  • sitename.com/sitepage?script2 > This would run script in script2.php
  • sitename.com/sitepage?script3 > This would run script in script3.php
  • Etc (if nothing than run nothing)

Code:
<script>
$(document).ready(function () {
  var scriptLocation = window.location.search.substring(1);
  $(document.body).append($("script").attr(src,scriptLocation));
)}
</script>

<script type="text/javascript" src="[URL]http://mydomain.com/xxxx.js[/URL]"></script>

Can anyone help me combine the two above please
 
Last edited by a moderator:
Code:
Added code tags for you.
 
Could not understand the question properly. You could maybe use .htaccess
Code:
RewriteEngine On
RewriteBase /
RewriteRule ^sitepage?script([0-9]+)$ script$1.php [L,QSA,NC]

The code runs script{N}.php when sitepage?script{N} is opened, {N} = any positive integer.
 
I'm trying to put together a code where script is run from another page based on the parameter, example:

  • sitename.com/sitepage?script1 > This would run script in script1.php
  • sitename.com/sitepage?script2 > This would run script in script2.php
  • sitename.com/sitepage?script3 > This would run script in script3.php
  • Etc (if nothing than run nothing)

Code:
<script>
$(document).ready(function () {
  var scriptLocation = window.location.search.substring(1);
  $(document.body).append($("script").attr(src,scriptLocation));
)}
</script>

<script type="text/javascript" src="[URL]http://mydomain.com/xxxx.js[/URL]"></script>

Can anyone help me combine the two above please
I guess what you are trying to achieve is to run the script remotely on another page when a particular link with parameters was visited by a user, correct me if I'm wrong. The answer for it is..., you can't.
 
I guess what you are trying to achieve is to run the script remotely on another page when a particular link with parameters was visited by a user, correct me if I'm wrong. The answer for it is..., you can't.

That's right. I've found a workaround and used document.write instead
 
I'm not entirely sure what you're trying to do, but you CAN run the PHP script in the background on ether load event for example or by overwriting the link event and making an AJAX request when user clicks the link and then make the link "act normal" again. You can also run it in a background from PHP's side, but I'm not sure what you're trying to do exactly, if you can give a little bit more info, I could explain the best way on doing this.
 
Last edited:
Back
Top