This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-09-11 04:30:43

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Web Coding Questions

Ok, I searched lots of sites, but didn't find the answer. I'm wondering how to I make it so that it automatically brings you to a webpage, without a link having to been clicked?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#2 2011-09-11 05:03:39

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Web Coding Questions

You mean like, when you go to a page, it automatically forwards you somewhere else?
Readsmile

Offline

 

#3 2011-09-11 05:28:52

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

Is there a code in javascript for

if contents_from_file("file url") = "selected contents"
{
   method
}


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#4 2011-09-11 05:56:49

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Code:

<?php
$fileContents = file_get_contents("URL to file");
?>
<script type = "text/javascript">
     if(<?php echo $fileContents; ?> == "selected contents"){
          code
     }
</script>

This is just off the top of my head. There may be a javascript equivalent to the php file_get_contents() method you can use rather than using a php variable.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#5 2011-09-11 07:09:27

whizzer
Scratcher
Registered: 2008-05-27
Posts: 500+

Re: Web Coding Questions

<meta>... hang on...


http://i46.tinypic.com/33df6me.png I'm whizzer0 for all things Minecraft.

Offline

 

#6 2011-09-11 07:26:16

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Web Coding Questions

put this in the <head> and </head> tags:

Code:

<script type="text/javascript">
window.location=('http://www.google.com')
</script>

change http://www.google.com to the website you want to redirect to

Last edited by nathanprocks (2011-09-11 07:26:56)


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#7 2011-09-11 07:33:52

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

nathanprocks wrote:

put this in the <head> and </head> tags:

Code:

<script type="text/javascript">
window.location=('http://www.google.com')
</script>

change http://www.google.com to the website you want to redirect to

Out of interest, does the js redirect allow variables in it? I've found that the php redirect function won't work if you try to put variables into the URL whilst thankfully the HTTP meta redirect function allows them  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2011-09-11 07:39:49

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

nathanprocks wrote:

put this in the <head> and </head> tags:

Code:

<script type="text/javascript">
window.location=('http://www.google.com')
</script>

change http://www.google.com to the website you want to redirect to

Out of interest, does the js redirect allow variables in it? I've found that the php redirect function won't work if you try to put variables into the URL whilst thankfully the HTTP meta redirect function allows them  tongue

like this?

Code:

<script type="text/javascript">
var google = "http://www.google.com"
window.location=(google)
</script>

http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#9 2011-09-11 07:41:55

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

more like

Code:

<script type="text/javascript">
var type = "Operators"
window.location=('http://www.somesite.com/typesearch?type=' + type)
</script>

http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#10 2011-09-11 07:47:48

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

more like

Code:

<script type="text/javascript">
var type = "Operators"
window.location=('http://www.somesite.com/typesearch?type=' + type)
</script>

yeah that would work!
search for 'variables' with google:

Code:

<script type="text/javascript">
var search = "variables"
window.location=('http://www.google.com/search?q=' + search)
</script>

and i also just found out that u can put spaces in google without using + in the address bar

Last edited by nathanprocks (2011-09-11 07:48:19)


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#11 2011-09-11 07:49:51

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Oh yes, a lot of search engines and search filters use + to indicate seperate search terms and _ to indicate two words that are part of a single search term like shirley_bassey+singer  smile


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#12 2011-09-11 07:52:05

nathanprocks
Scratcher
Registered: 2011-04-14
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Oh yes, a lot of search engines and search filters use + to indicate seperate search terms and _ to indicate two words that are part of a single search term like shirley_bassey+singer  smile

lol i put a space in the search variable between two words and it changed to %20 which also works  big_smile  i always thought u had to put +


http://carrot.cassiedragonandfriends.org/Scratch_Signature/randomsig.php
http://trinary.site40.net/images/scratchrank.php?username=nathanprocks&amp;display=small

Offline

 

#13 2011-09-11 08:28:24

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

I am making a thing using HTML, and javascript and some php. But when it starts, the login box doesn't appear. Here's teh code (please don't steal it):

Code:

<script type="text/javascript">
<!--
window.location = "javascript:login()"
//-->
</script>

<script type="text/javascript">
function login()
{
var username=prompt("Please enter your username:");
var password=prompt("Please enter your password:");
}
</script>

<?php
$fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" + username + "&password=" + password);
?>
<script type = "text/javascript">
     if(<?php echo $fileContents; ?> == "false"){
          <?php echo "Invalid Details" ?>
     }
     else {

     } </script>
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter a username:");
var projectid=prompt("Please enter a project ID:");
if (projectid!=null && projectid!="")
  {
  window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid;
  }
}
</script>
</head>
<body>

<input type="button" onclick="show_prompt()" value="Open a Project" />

</body>
</html>

http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#14 2011-09-11 08:34:22

Hardmath123
Scratcher
Registered: 2010-02-19
Posts: 1000+

Re: Web Coding Questions

WindowsExplorer wrote:

I am making a thing using HTML, and javascript and some php. But when it starts, the login box doesn't appear. Here's teh code (please don't steal it):

Code:

<script type="text/javascript">
login() // Error here (I think).
</script>

<script type="text/javascript">
function login()
{
var username=prompt("Please enter your username:");
var password=prompt("Please enter your password:");
}
</script>

<?php
$fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" + username + "&password=" + password);
?>
<script type = "text/javascript">
     if(<?php echo $fileContents; ?> == "false"){
          <?php echo "Invalid Details" ?>
     }
     else {

     } </script>
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter a username:");
var projectid=prompt("Please enter a project ID:");
if (projectid!=null && projectid!="")
  {
  window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid;
  }
}
</script>
</head>
<body>

<input type="button" onclick="show_prompt()" value="Open a Project" />

</body>
</html>

Hardmaths-MacBook-Pro:~ Hardmath$ sudo make $(whoami) a sandwich

Offline

 

#15 2011-09-11 09:02:52

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Web Coding Questions

WindowsExplorer wrote:

I am making a thing using HTML, and javascript and some php. But when it starts, the login box doesn't appear. Here's teh code (please don't steal it):

Code:

<script type="text/javascript">
<!--
window.location = "javascript:login()"
//-->
</script>

<script type="text/javascript">
function login()
{
var username=prompt("Please enter your username:");
var password=prompt("Please enter your password:");
}
</script>

<?php
$fileContents = file_get_contents("http://scratch.mit.edu/api/authenticateuser?username=" + username + "&password=" + password);
?>
<script type = "text/javascript">
     if(<?php echo $fileContents; ?> == "false"){
          <?php echo "Invalid Details" ?>
     }
     else {

     } </script>
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Please enter a username:");
var projectid=prompt("Please enter a project ID:");
if (projectid!=null && projectid!="")
  {
  window.location = "http://scratch.mit.edu/projects/" + name + "/" + projectid;
  }
}
</script>
</head>
<body>

<input type="button" onclick="show_prompt()" value="Open a Project" />

</body>
</html>

It's quite obvious that you need

Code:

<body onload="login()">

instead of

Code:

<script type="text/javascript">
<!--
window.location = "javascript:login()"
//-->
</script>

wink

Offline

 

#16 2011-09-11 09:04:52

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Code:

<?php
$fileContents = file_get_contents("URL to file");
?>
<script type = "text/javascript">
     if(<?php echo $fileContents; ?> == "selected contents"){
          code
     }
</script>

This is just off the top of my head. There may be a javascript equivalent to the php file_get_contents() method you can use rather than using a php variable.

It doesn't work.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#17 2011-09-11 09:14:37

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Hmmm, well I haven't tested it but I can't see anything wrong with it. you could try putting the php echo in the if statement into speech marks, otherwise your contents might be what's causing the problem, not the statement above.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#18 2011-09-11 09:19:53

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

Still not working.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#19 2011-09-11 09:27:51

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

Then I have no idea, I'm afraid.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#20 2011-09-11 09:58:48

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Then I have no idea, I'm afraid.

Exact phrasing much? [ tongue ]

Last edited by LS97 (2011-09-11 09:59:03)

Offline

 

#21 2011-09-11 09:59:21

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Then I have no idea, I'm afraid.

I need it for making a thing where you need to login with your Scratch account.  sad


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#22 2011-09-11 10:02:14

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

Then I have no idea, I'm afraid.

It doesn't work because you forgot to add javascript double quotes outside the PHP echo.

Offline

 

#23 2011-09-11 10:02:55

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

LS97 wrote:

sparks wrote:

Then I have no idea, I'm afraid.

Exact phrasing much? [ tongue ]

Okay so I'm clueless twice in one day. I can only assume it's good for me!  tongue


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#24 2011-09-11 10:06:18

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Web Coding Questions

LS97 wrote:

sparks wrote:

Then I have no idea, I'm afraid.

It doesn't work because you forgot to add javascript double quotes outside the PHP echo.

sparks wrote:

Hmmm, well I haven't tested it but I can't see anything wrong with it. You could try putting the php echo in the if statement into speech marks, otherwise your contents might be what's causing the problem, not the statement above.

WindowsExplorer wrote:

Still not working.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#25 2011-09-11 10:09:56

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Web Coding Questions

sparks wrote:

LS97 wrote:

sparks wrote:

Then I have no idea, I'm afraid.

It doesn't work because you forgot to add javascript double quotes outside the PHP echo.

sparks wrote:

Hmmm, well I haven't tested it but I can't see anything wrong with it. You could try putting the php echo in the if statement into speech marks, otherwise your contents might be what's causing the problem, not the statement above.

WindowsExplorer wrote:

Still not working.

oh, oops.

Anyway, why don't you just use PHP since you can?

header('Location')?

Offline

 

Board footer