melvnberd
melvnberd

Reputation: 3163

javascript arent working before calling return redirect

I was wondering why my script file wasn't functioning here's my code:

$l2 = "<script>";
$l2 = $l2."window.open('http://sampleurl.dev/purchase_order/";
$l2 = $l2.$id;
$l2 = $l2."/pdf')</script>";
echo $l2;
return Redirect::action('SuppliersController@show',$supplierId);

but if I put die(); before the redirect the script is then functioning but I cant proceed to redirect anymore.

by the way I'm echoing $l2 to open a new window for my pdf view.

your help would really be appreciated!

Upvotes: 0

Views: 57

Answers (1)

Guffa
Guffa

Reputation: 700422

You can't send both a content page and a redirect page in the same response. When you send the redirect, it will scrap any content that you have created for the page.

You can make a redirect in the client script:

echo "<script>window.open('http://sampleurl.dev/purchase_order/".$id."/pdf');window.location.href='somepage';</script>";

Upvotes: 1

Related Questions