Split / merge tabs in Safari

Is there any way to split a/o merge tabs in Safari? I don’t mean to put two windows side by side, but split them in the same view.

I checked the dictionary to no avail and I cannot come up with a workaround. Also, I haven’t found any reference here.

Btw, first post ” hi there! :slight_smile:

Browser: Safari 537.74.9
Operating System: Mac OS X (10.8)

I found some js that would help to split a tab using two frames, but I cannot make it work. Probably I’m getting the escaping wrong. If someone lends a hand. :slight_smile:

-- http://www.chromeplugins.org/plugins/google-chrome-dual-view/

(*
javascript:A14nH=location.href;L3f7=prompt('Choose%20File%201',A14nH);R1Gh7=prompt('Choose%20File%202',L3f7);if(L3f7&&R1Gh7){Fr4Q='<frameset%20cols=\'*,*\'>\n<frame%20src=\''+L3f7+'\'/>';Fr4Q+='<frame%20src=\''+R1Gh7+'\'/>\n';Fr4Q+='</frameset>';with(document){write(Fr4Q);void(close())}}else{void(null)}
*)

tell application "Safari"
	activate
	tell front window
		if (count of tabs) ≥ 2 then
			set TabsURLs to URL of tabs
			set CurrentTabIndex to index of current tab
			set LeftTab to item (CurrentTabIndex - 1) of TabsURLs
			set RightTab to item CurrentTabIndex of TabsURLs
			set theScript to "" -- here js
			make new tab at end
			do JavaScript theScript in last tab
			set current tab to last tab
		end if
	end tell
end tell
tell application "Safari"
	activate
	if front window exists then tell front window
		if (count of tabs) ≥ 2 then
			if (count of tabs) = 2 then set current tab to last tab
			set TabsURLs to URL of tabs
			set CurrTabIndex to index of current tab
			set LeftTabURL to quoted form of (item (CurrTabIndex - 1) of TabsURLs)
			set RightTabURL to quoted form of (item CurrTabIndex of TabsURLs)
			set theJavaScript to "if(" & LeftTabURL & "&&" & RightTabURL & "){
			FrameSet='<frameset cols=\\'*,*\\'>\\n<frame src=\\''+" & LeftTabURL & "+'\\'/>';
			FrameSet+='<frame src=\\''+" & RightTabURL & "+'\\'/>\\n';
			FrameSet+='</frameset>';
			with(document){write(FrameSet);
			void(close())}}else{void(null)}"
			do JavaScript theJavaScript in current tab
		end if
	end tell
end tell

It doesn’t work with all sites, so YMWV.

Welcome to MacScripters!

I like your script, especially with full screen (haven’t tried that yet), as it makes a lot of sense to see two web-pages at a time, (and maybe more).

Anyways, I scavenged your script and created one that resets the current tab to just display what’s in it.

Thank you very much, once again for this. :slight_smile:

tell application "Safari"
	activate
	if front window exists then tell front window
		if (count of tabs) ≥ 2 then
			if (count of tabs) = 2 then set current tab to last tab
			set TabsURLs to URL of tabs
			set CurrTabIndex to index of current tab
			set RightTabURL to quoted form of (item CurrTabIndex of TabsURLs)
			set theJavaScript to "if(" & RightTabURL & "){
           FrameSet='<frameset cols=\\'\\'>\\n<frame src=\\''+" & RightTabURL & "+'\\'/>';
           FrameSet+='</frameset>';
           with(document){write(FrameSet);
           void(close())}}else{void(null)}"
			do JavaScript theJavaScript in current tab
		end if
	end tell
end tell

I just use ⌘L then ↩ and spare a shortcut and fainting memory :wink:

Btw, if you want to split horizontally just change in the js cols to rows.

In the post above I stated YMWV ” I meant, if you get a X-Frame-Options header with values SAMEORIGIN or DENY then it won’t work.

I don’t do HTML that much anymore, does anyone know a workaround?